<template>
  <el-dialog
    :model-value="props.sAccountVisible"
    title="增加核算方案"
    width="25%"
    :before-close="handleClose"
  >
    <div class="scheme-form">
      <el-form
        ref="ruleFormRef"
        :rules="rules"
        :model="form"
        label-width="120px"
      >
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="handleClose">返回</el-button>
        <el-button type="primary" @click="handle(ruleFormRef)">
          确定
        </el-button>
      </span>
    </template>
  </el-dialog>
</template>
<script setup>
import { ref, reactive, onMounted } from "vue";
import { useAppStore } from "@/stores";
import { meterPositionPlanSave } from "@/api/app.js";

import { storeToRefs } from "pinia";

const useApp = useAppStore();
let { organStructure } = storeToRefs(useApp);

const emit = defineEmits(["is-show", "doAddSAccount"]);
const props = defineProps({
  sAccountVisible: Boolean,
  form: Object,
});
const rules = reactive({
  name: [{ required: true, message: "请输入方案名称", trigger: "blur" }],
});
const ruleFormRef = ref();

const handleClose = () => {
  emit("is-show");
};
//点击确定
const handle = (formEl) => {
  if (!formEl) return;
  formEl.validate((valid, fields) => {
    if (valid) {
      let parm = {
        name: props.form.name,
      };
      emit("doAddSAccount", parm);
    } else {
      console.log("error submit!", fields);
    }
  });
};
</script>
<style lang="scss" scoped>
.ele-type {
  display: flex;
  .ele-type-item1 {
    width: 390px;
  }
  .ele-type-item2 {
    flex: 1;
  }
}
.dialog-footer {
  display: flex;
  justify-content: center;
  .el-button {
    width: 60px;
  }
}
</style>
